import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[]array={1,9,2,8,3,7,4,6,5};
        bubbleSort(array);
        //selectSort(array);
        System.out.println(Arrays.toString(array));
    }

    private static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            boolean flag =false;
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j]> array[j+1]){
                    flag = true;
                    swap(array,j,j+1);
                }
            }
            if(!flag)
                 break;
        }
    }

    private static void selectSort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            int minIndex = i;
            for (int j = i+1; j < array.length ; j++) {
                if(array[j]<array[minIndex]){
                    minIndex = j;
                }
            }
            swap(array,i,minIndex);
        }
    }

    private static void swap(int[] array, int a, int b) {
        int tmp = array[a];
        array[a] = array[b];
        array[b] = tmp;
    }
}
